/**
 * 
 */
package edu.hawaii.library.uh;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
//import org.junit.Ignore;
import org.junit.Test;
import edu.hawaii.duedates.book.Book;

/**
 * Tests the UhManoa class and its methods.
 * 
 * @author John Zhou
 * 
 */
public class TestUhLibrary {
  // the id and lastname arguments passed in at command-line
  private final String id1 = System.getenv("DUEDATES_TESTUSER1_ID");
  private final String id2 = System.getenv("DUEDATES_TESTUSER2_ID");
  private final String lastName1 = System.getenv("DUEDATES_TESTUSER1_LASTNAME");
  private final String lastName2 = System.getenv("DUEDATES_TESTUSER2_LASTNAME");
  private List<Book> bookList = new ArrayList<Book>();

  /**
   * Test getInfo (which also calls login) with account with no books.
   * @throws Exception If error logging in.
   */
  
  @Test
  public void testGetInfoNoBooks() throws Exception {
    UhLibrary uhLib = new UhLibrary();
    bookList = uhLib.getInfo(this.id1, this.lastName1, bookList);
    assertTrue("Testing getInfo with no books", bookList.isEmpty());
  }
  
  /**
   * Test getInfo (which also calls login) with account with books.
   * @throws Exception If error logging in.
   */
  @Test
  public void testGetInfoWithBooks() throws Exception {
    UhLibrary uhLib = new UhLibrary();
    bookList = uhLib.getInfo(this.id2, this.lastName2, bookList);
    assertFalse("Testing getInfo with books", bookList.isEmpty());
  }

  /**
   * Test login with a bad account arguments.
   * 
   * @throws Exception When error logging in.
   */
  @Test(expected = Exception.class)
  public void testIllegalLogin() throws Exception {
    UhLibrary uhLib = new UhLibrary();
    uhLib.login("", "");
    fail("Invalid account login passed");
  }
  
  /**
   * Test convertDateToCalendar.
   */
  @Test
  public void testConvertDateCalendar () {
    UhLibrary uhLib = new UhLibrary();
    Calendar cal = uhLib.convertDateToCalendar("22210-11-08");
    //Calendar month is zero-based.  So January is 0, February is 1, etc.
    assertEquals("Testing Month of Calendar", cal.get(Calendar.MONTH), 9);
    assertEquals("Testing Day of Calendar", cal.get(Calendar.DAY_OF_MONTH), 11);
    assertEquals("Testing Year of Calendar", cal.get(Calendar.YEAR), 2008);    
  }
  
  /**
   * Test getName.
   */
  @Test
  public void testGetName() {
    UhLibrary uhLib = new UhLibrary();
    assertEquals("Testing Name.", uhLib.getName(), "University of Hawaii");
  }
}
